package auxilary;

import database.Tables;

public class Constants {
	public static final class Group {
		public static final int NUM_OF_GROUPS = 6;
		public static final String getName(int groupId) {
			switch (groupId) {
				case MAGIC :
					return "Magic";
				case SPORT :
					return "Sport";
				case HOUSEHOLD :
					return "Household";
				case FOOD :
					return "Food";
				case CLOTHES :
					return "Clothes";
				case RESTING :
					return "Resting";
				default :
					return "Group-"+String.valueOf(groupId-NUM_OF_GROUPS+1);
			}
		}
		public static final int MAGIC = 0;
		public static final int SPORT = 1;
		public static final int HOUSEHOLD = 2;
		public static final int FOOD = 3;
		public static final int CLOTHES = 4;
		public static final int RESTING = 5;
	}

	public static final class Queries {
		public static final String FULL_IDS = "SELECT `" + Tables.Course.Columns.ID + "` FROM "
				+ " (SELECT " + Tables.Course.dbName + ".`"
				+ Tables.Course.Columns.ID + "`," + Tables.Course.dbName + ".`"
				+ Tables.Course.Columns.CAPACITY + "`, COUNT(*) AS `c` FROM "
				+ Tables.Course.fullDBName + "," + Tables.User.fullDBName
				+ ", " + Tables.CourseToUser.fullDBName + " WHERE "
				+ Tables.Course.fullDBName + ".`" + Tables.Course.Columns.ID
				+ "`=" + Tables.CourseToUser.fullDBName + ".`"
				+ Tables.CourseToUser.Columns.COURSE_ID + "` AND "
				+ Tables.User.fullDBName + ".`" + Tables.User.Columns.ID + "`="
				+ Tables.CourseToUser.fullDBName + ".`"
				+ Tables.CourseToUser.Columns.USER_ID + "` AND "
				+ Tables.CourseToUser.fullDBName + ".`"
				+ Tables.CourseToUser.Columns.IS_REGISTERED + "`=1 GROUP BY "
				+ Tables.Course.Columns.ID + " HAVING "
				+ Tables.Course.fullDBName + ".`"
				+ Tables.Course.Columns.CAPACITY + "`=`c`) AS `b`";
	}
	
	public static final String truncate(String str, int len) {
		if (str.length() > len) {
			return str.substring(0, len-2) + "...";
		} else {
			return str;
		}
	}
}
